<?php
/**
 * Stores files in self::$fileDir (ex."files") using unique names on save
 * allowing only one file (substituting)
 */
class PlFileListWidget extends UploadWidget {
    const  UPLOAD_ACTION    = 'upload';
    const  DELETE_ACTION    = 'delete';
    const  FILE_LIST_ACTION = 'fileList';

    /** File list  */
    public function run() {
        $model = $this->getOwner();
        if (isset($model)) {
            // Temporal files in session + files associated to the model
            $tempFiles = UploadUtils::getSessionFiles();
            $files = UploadUtils::findFiles(get_class($this->model), $this->model->getPrimaryKey());
            $files = array_merge($files, $tempFiles);
            $this->getController()->renderPartial('ext.upload.plupload.views.fileList', array('files'=>$files));
        } elseif (isset($_REQUEST['entity']) && isset($_REQUEST['EXid'])) {
            $files = UploadUtils::findFiles($_REQUEST['entity'], $_REQUEST['EXid']);
            $this->getController()->renderPartial('ext.upload.plupload.views.fileList', array('files'=>$files));
        }
    }

}